jMass.Dictionary = jMass.define({
    guid: 0,
    $items: {},
    constructor: function () {
        this.guid = ++jMass.guid;
        this.$items = {};
    },
    length: function () {
        return this.$items.length;
    },
    get: function (key) {
        return this.$items[key];
    },
    set: function (key, value) {
        this.$items[key] = value;
    },
    remove: function (key) {
        delete this.$items[key];
    },
    clear: function () {
        this.$items = {};
    },
    containsKey: function (key) {
        return this.$items.hasOwnProperty(key);
    },
    containsValue: function (value) {
        for (var key in this.$items)
            if (this.$items.hasOwnProperty(key))
                if (this.$items[key] === value)
                    return true;
        return false;
    },
    getKeys: function () {
        var result = [];
        for (var key in this.$items)
            if (this.$items.hasOwnProperty(key))
                result[result.length] = key;
        return result;
    },
    getValues: function () {
        var result = [];
        for (var key in this.$items)
            if (this.$items.hasOwnProperty(key))
                result[result.length] = this.$items[key];
        return result;
    },
    toEnum: function () {
        return new jMass.Enum.DictionaryEnumerator(this);
    }
});

/* Dictionary enumerator */
var dictEnum = BaseEnum.extend({
    name: "dict",
    $index: -1,
    $keys: [],
    prepare: function () {
    },
    next: function () {
        if (this.$index < this.$keys.length - 1) {
            this.current = { key: this.$keys[i] };
            this.current.value = this.source[this.current.key];
            return true;
        }
        this.current = null;
        return false;
    },
    reset: function () {
        this.keys = this.source.getKeys();
        this.$index = -1;
        this.current = null;
    }
});
jMass.regEnumClass("Dictionary", dictEnum);
